package com.zj.utils;

import com.zj.exception.TypeException;
import com.zj.sqlSession.DefaultSqlSessionFactory;
import com.zj.sqlSession.SqlSessionFactory;
import org.dom4j.io.SAXReader;

import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

public class SqlSessionFactoryBuilder {
    public SqlSessionFactoryBuilder() {
    }

    public SqlSessionFactory build(Reader reader) {
        return this.build((Reader)reader, (String)null, (Properties)null);
    }

    public SqlSessionFactory build(Reader reader, String environment) {
        return this.build((Reader)reader, environment, (Properties)null);
    }

    public SqlSessionFactory build(Reader reader, Properties properties) {
        return this.build((Reader)reader, (String)null, properties);
    }

    public SqlSessionFactory build(Reader reader, String environment, Properties properties) {
        SqlSessionFactory var5;
        try {
            XMLConfigBuilder parser = new XMLConfigBuilder(new SAXReader().read(reader), environment, properties);
            Configuration cfg=parser.parse();
            var5 = this.build(cfg);
        } catch (Exception var14) {
            throw new TypeException("Error building SqlSession.", var14);
        } finally {

            try {
                reader.close();
            } catch (IOException var13) {
                ;
            }

        }

        return var5;
    }

    public SqlSessionFactory build(Configuration config) {
        return new DefaultSqlSessionFactory(config);
    }
}
